package com.ruoyi.fetv.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.aspect.annotation.AutoDict;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.fetv.controller.vo.image.AddReq;
import com.ruoyi.fetv.controller.vo.image.EditReq;
import com.ruoyi.fetv.domain.FetvImage;
import com.ruoyi.fetv.service.IFetvImageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 图片Controller
 *
 * @author Jack
 * @date 2023-03-07
 */
@Api(value = "/fetv/image", tags = {"图片管理"})
@RestController
@RequestMapping("/fetv/image")
@Validated
@AutoDict
public class FetvImageController extends BaseController {
    @Autowired
    private IFetvImageService fetvImageService;

    /**
     * 查询图片列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "FetvImage", name = "fetvImage", value = "", required = true)
    })
    @ApiOperation(value = "查询图片列表", notes = "查询图片列表", httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('fetv:image:list')")
    @ApiResponse(code = 200, message = "", response = TableDataInfo.class)
    @GetMapping("/list")
    public TableDataInfo<List<FetvImage>> list(FetvImage fetvImage) {
        startPage();
        List<FetvImage> list = fetvImageService.selectFetvImageList(fetvImage);
        return getDataTable(list);
    }

    /**
     * 获取图片详细信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "id", value = "", required = true)
    })
    @ApiOperation(value = "获取图片详细信息", notes = "获取图片详细信息", httpMethod = "GET")
    @PreAuthorize("@ss.hasPermi('fetv:image:query')")
    @GetMapping(value = "/{id}")
    @ApiResponse(code = 200, message = "", response = FetvImage.class)
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        FetvImage data = fetvImageService.selectFetvImageById(id);
        if (data == null) {
            throw new ServiceException("不存在的ID");
        }
        return success(data);
    }

    /**
     * 新增图片
     */

    @ApiOperation(value = "新增图片信息", notes = "新增图片信息", httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('fetv:image:add')")
    @Log(title = "图片", businessType = BusinessType.INSERT)
    @ApiResponse(code = 200, message = "成功操作的数量", response = int.class)
    @PostMapping
    public AjaxResult add(@ApiParam(name = "fetvImage", value = "图片信息", required = true) @RequestBody @Valid AddReq fetvImage) {
        return toAjax(fetvImageService.insertFetvImage(fetvImage));
    }

    /**
     * 修改图片
     */

    @ApiOperation(value = "修改图片", notes = "修改图片", httpMethod = "PUT")
    @PreAuthorize("@ss.hasPermi('fetv:image:edit')")
    @Log(title = "图片", businessType = BusinessType.UPDATE)
    @ApiResponse(code = 200, message = "成功操作的数量", response = int.class)
    @PutMapping
    public AjaxResult edit(@ApiParam(name = "fetvImage", value = "图片信息", required = true) @RequestBody @Valid EditReq fetvImage) {
        return toAjax(fetvImageService.updateFetvImage(fetvImage));
    }

    /**
     * 删除图片
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "Long[]", name = "ids", value = "", required = true)
    })
    @ApiOperation(value = "删除图片", notes = "删除图片", httpMethod = "DELETE")
    @PreAuthorize("@ss.hasPermi('fetv:image:remove')")
    @Log(title = "图片", businessType = BusinessType.DELETE)
    @ApiResponse(code = 200, message = "成功操作的数量", response = int.class)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(fetvImageService.deleteFetvImageByIds(ids));
    }
}
